//
//  Service+Activity.m
//  CarService
//
//  Created by fengyn on 15/6/23.
//  Copyright (c) 2015年 lexingsoft. All rights reserved.
//

#import "Service+Activity.h"

@implementation ServiceManager(Activity)


///查询每日一篇
+ (void)getAllNewsWithPageIndex:(NSUInteger)pageIndex businessType:(NSString *)businessType success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/content/information/page";
    const int countPer=20;
    NSDictionary * dict = @{@"start":@(pageIndex*countPer),
                            @"length":@(countPer),
                            @"businessType":businessType};
    [NetworkClient getRequest:path parameters:dict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        
    }];
}
///查询所有资讯(分页)
+ (void)getAllNewsWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/content/information/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer)};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///根据ID获取资讯的详细信息
+ (void)getNewsDetailWithId:(NSString *)newsId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"%@/%@",@"/content/information",newsId];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///对资讯点赞
+ (void)upvoteNewsWithId:(NSString *)newsId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    if ([ServiceManager isUpvotedNewsWithID:newsId]) {
        DLog(@"已经对该资讯点过赞");
        return;
    }
    NSString *newsKey=[ServiceManager newsKeyWithId:newsId];
    [[NSUserDefaults standardUserDefaults] setObject:newsKey forKey:newsKey];
    
    NSString *path = [NSString stringWithFormat:@"%@/%@/upvote",@"/content/information",newsId];
    NSDictionary *parameterDict=nil;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///活动Key
+ (NSString *)newsKeyWithId:(NSString *)newsId
{
    return [NSString stringWithFormat:@"newsID%@",newsId];
}

///是否已对资讯点过赞
+ (BOOL)isUpvotedNewsWithID:(NSString *)newsId
{
    BOOL isValue = NO;
    NSString *newsKey=[ServiceManager newsKeyWithId:newsId];
    NSString *newsValue=[[NSUserDefaults standardUserDefaults] objectForKey:newsKey];
    if (newsValue) {
        isValue=YES;
    }
    return isValue;
}

///查询所有活动(分页)
+ (void)getAllActivitysWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/content/activity/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer)};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///根据ID获取活动的详细信息
+ (void)getActivityDetailWithId:(NSString *)newsId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"%@/%@",@"/content/activity",newsId];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///活动报名
+ (void)signupActivityWithId:(NSString *)newsId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"%@/%@/signup",@"/content/activity",newsId];
    NSDictionary *parameterDict=nil;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///活动感兴趣
+ (void)interestActivityWithId:(NSString *)newsId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    if ([ServiceManager isInteresedActivityWithId:newsId]) {
        DLog(@"已经对该活动感过兴趣");
        return;
    }
    NSString *newsKey=[ServiceManager activityKeyWithId:newsId];
    [[NSUserDefaults standardUserDefaults] setObject:newsKey forKey:newsKey];
    
    NSString *path = [NSString stringWithFormat:@"%@/%@/interest",@"/content/activity",newsId];
    NSDictionary *parameterDict=nil;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///是否已对活动感兴趣过
+ (BOOL)isInteresedActivityWithId:(NSString *)newsId
{
    BOOL isValue = NO;
    NSString *activityKey=[ServiceManager activityKeyWithId:newsId];
    NSString *activityValue=[[NSUserDefaults standardUserDefaults] objectForKey:activityKey];
    if (activityValue) {
        isValue=YES;
    }
    return isValue;
}

///活动Key
+ (NSString *)activityKeyWithId:(NSString *)newsId
{
    return [NSString stringWithFormat:@"activityID%@",newsId];
}

///获取中奖信息
+ (void)getWinningInfoWithSuccess:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/scoreevent";
    NSDictionary * dic = @{@"scoreEventType":@"SWEEPSTAKE"};
    [NetworkClient getRequest:path parameters:dic NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        failure(dataObject);
    }];
}
///获取具体中了几等奖
+ (void)getWinningResultsWithSuccess:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/scoreevent/sweepstake";
    NSDictionary * dic = nil;
    [NetworkClient postRequest:path parameters:dic NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///测试资讯
+ (void)postActivityWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = @"/back/mobile/zixun/list/jqzx";
    const int countPer=20;
    NSDictionary * dict = @{@"page":@(pageIndex*countPer),
                            @"rows":@(countPer)};
    [NetworkClient postRequest:path parameters:dict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        
    }];

}
///广告页
+ (void)postBannerWithSuccess:(void(^)(NSDictionary*data)) success failure:(void(^)(NSDictionary*data))failure
{
    NSString * path = @"/back/mobile/guanggao/info";
    NSDictionary * dic = nil;
    [NetworkClient postRequest:path parameters:dic NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
///测试资讯详情
+ (void)postActivityDetailsWithString:(NSString*)Id success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = [NSString stringWithFormat:@"/back/mobile/zixun/item/%@",Id];
    NSDictionary * dic = nil;
    [NetworkClient postRequest:path parameters:dic NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///测试功能栏
+ (void)getFunctionalClassificationWithSuccess:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"/menu/query.do"];
    NSDictionary * dic = nil;
    [NetworkClient postRequest:path parameters:dic NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
@end
